//
//  AddressSelector.swift
//  glive
//
//  Created by zhuxietong on 2020/8/13.
//  Copyright © 2020 zhu xietong. All rights reserved.
//

import Foundation
import Eelay
public class AddressSelector: GesSideController{
        
    
    public var address:[String] = []{
        didSet{
            ctr.address = address
        }
    }
    
    
    
    let ctr = AddressTabCtr()
//    let deleteBt = UIButton()

    
    public override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
//        _ = deleteBt.ui.padding(insets: [4]).nimage(UIImage(named: "delete-border")?.dynamicImage(color: .color(light: "#888", dark: "#fff9"))).background(color: .color(light: "#f0f0f0", dark: "#ddd2")).set(radius: 10, width: nil, color: nil)
//        let img = UIImage(named:"delete_tag")?.dynamicImage(color: .color(light: "#333", dark: "#fff9"))
//                deleteBt.setImage(img, for: .normal)

    }
    
    let deleteBt = UIImageView()
    public var confirm:(_:NSMutableDictionary,_:NSMutableArray)->Void = {_,_ in}
    
    public override func viewDidLoad() {
        
        self.side = .bottom(height: (Sheight * 0.80))
        super.viewDidLoad()
        ctr.confirm = {[weak self] item,list in
            co_delay(delay: 0.1) {
                self?.close()
            }
           
            self?.confirm(item,list)
        }
        floatBack.bsui.set(radius: 15, width: nil, color: nil)
        
        let label = UILabel()
        ctr.willMove(toParent: self)
        self.addChild(ctr)
        if let v = ctr.view{
            jo_contentView.eelay = [
                [label,[ee.T.L.R,[20.co,22.co,-80]]],
                [deleteBt,[label,ee.Y],[ee.R,-20.co],20,"20"],
                [v,[ee.L.B.R],[label,ee.B,ee.T,8]]
            ]
        }
        ctr.didMove(toParent: self)
        deleteBt.isUserInteractionEnabled = true
        deleteBt.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(close)))
        
//        _ = deleteBt.ui.padding(insets: [4]).nimage(UIImage(named: "delete-border")?.dynamicImage(color: .color(light: "#888", dark: "#fff9"))).background(color: .color(light: "#f0f0f0", dark: "#ddd2")).set(radius: 10, width: nil, color: nil)
        
        let img = UIImage(named:"delete_tag")?.dynamicImage(color: .color(light: "#333", dark: "#fff9"))
        deleteBt.image = img
//          deleteBt.setImage(img, for: .normal)
//        deleteBt.addTarget(self, action: #selector(close_selector), for: .touchUpInside)
        floatBack.backgroundColor = ._background
        _ = label.ui.font19.text(color: ._foreground).text("请选择地区").left
     
    }
    
    @objc func close_selector() {
        self.close()
    }

}
